package com.caipiao.crawler.run;

import com.caipiao.constant.CrawlerConstants;
import com.caipiao.crawler.daletou.DaletouResultPage;
import com.caipiao.crawler.daletou.DaletouResultPipeline;
import com.caipiao.crawler.jingqiucai.JingqiucaiResultPage;
import com.caipiao.crawler.jingqiucai.JingqiucaiResultPipeline;
import com.caipiao.crawler.qixingcai.QixingcaiResultPage;
import com.caipiao.crawler.qixingcai.QixingcaiResultPipeline;
import com.caipiao.crawler.shengfucang.ShengfucangResultPage;
import com.caipiao.crawler.shengfucang.ShengfucangResultPipeline;
import us.codecraft.webmagic.Spider;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by adminitrator on 2018/7/28.
 */
public class Jingqiucai implements RunCrawler {

    @Override
    public void run() {
        Spider.create(new JingqiucaiResultPage())
                .addUrl(CrawlerConstants.JINGQIUCAI_HISTORY_URL)
                .addPipeline(new JingqiucaiResultPipeline())
                .thread(4)
                .run();
    }

    @Override
    public void runHistory() {
        List<String> urls = new ArrayList<String>();
        for (int i = 18068; i < 18098; i++) {
            urls.add(CrawlerConstants.JINGQIUCAI_DATA_URL + i);
        }
        Spider.create(new JingqiucaiResultPage())
                .addUrl(urls.toArray(new String[0]))
                .addPipeline(new JingqiucaiResultPipeline())
                .thread(4)
                .run();
    }

    public void runNowMatch(){
        //获取当前比赛期数
        String url = CrawlerConstants.JINQIUCAI_NOW_MATCHLIST_URL;
        Spider.create(new JingqiucaiResultPage())
                .addUrl(url)
                .addPipeline(new JingqiucaiResultPipeline())
                .thread(4)
                .run();

    }
}
